even though i assigned a date to the variable, I receive the error message "getMonth is not a function"
Obviously the interpretor does not accept the type of date.
This is th relevant section of the code:
function init(){
var m=document.getElementById("m");
var d = Date();
refresh(d);
}
function refresh(d) {
var month = d.getMonth();
yes, the function is terminated by a } there are more lines to it, but it stops exactly there.
You forgot to use new keyword with Date :
function init(){
var m=document.getElementById("m");
var d = new Date();
refresh(d);
}
function refresh(d) {
var month = d.getMonth();
console.log(month)
}
init()
You seem to want to get the constructor, while you're currently defining the function as d.
Read more about Date here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
So, the code fragment should be:
function init(){
var m=document.getElementById("m");
var d = new Date();
refresh(d);
}
function refresh(d) {
var month = d.getMonth();
Date is a class in javascript, so you need to use the new keyword to create a new instance and call methods like getMonth on it.
function init(){
var m=document.getElementById("m");
var d = new Date();
refresh(d);
}
function refresh(d) {
var month = d.getMonth();
console.log(month);
}
init();